<template>
	<view class="Site">
		<view class="site_tab">
			<view class="tab_for" v-for="(item,index) in tabList" :class="indexValue == item.indexValue?'ShowValue':''"
				@click="ClickSite(item.indexValue)">
				{{item.name}}
			</view>
		</view>
		<view class="Scrview">
			<scroll-view class="scroll" scroll-y="true">
				<view class="Scrview_info" v-for="(item,index) in SiteList">
					<view class="shop_info">
						<view class="shop_image" @click="dianji(item)">
							<image :src="util.imageApi+item.goodsImg"></image>
						</view>
						<view class="shop_goodsinfo">
							<view class="shop_price">
								{{item.goodsName}}
								￥{{item.price}}
							</view>
							<view class="shop_num">
								数量：x{{item.num}}
							</view>
							<view class="Public_PRICE">
								￥{{item.Gjmoeny}}
							</view>
							<view class="">
								<view class="public_button" v-if="item.status == 8">
									已退款
								</view>
								<view class="public_button" v-if="item.status == 7">
									部分退款
								</view>
								<view class="public_button" v-if="item.status == 6">
									待审核
								</view>
								<view class="public_button" v-if="item.status == 5">
									已失效
								</view>
								<view class="public_button" v-if="item.status == 4">
									已完成
								</view>
								<view class="public_button" v-if="item.status == 3">
									待评价
								</view>
								<view class="public_button" v-if="item.status == 2">
									待收货
								</view>
								<view class="public_button" v-if="item.status == 1">
									待发货
								</view>
								<view class="public_button" v-if="item.status == 0">
									待付款
								</view>
								<view class="public_button" v-if="item.status == -1">
									拒收
								</view>
							</view>
							<view>
								<view class="public_button" v-if="item.status == 0">
									<u-button :plain="true" shape="circle" text="取消订单" @click="DelOrder(item)">
									</u-button>
									<u-button :plain="true" type="warning" shape="circle" text="确认支付"
										@click="Gopay(item)"></u-button>
								</view>
								<view class="public_button" v-if="item.status == 2">
									<u-button :plain="true" shape="circle" text="确认收货" @click="qrSH(item)"></u-button>
								</view>
								<view class="public_button" v-if="item.status == 3">
									<u-button :plain="true" @click="Pj(item)" shape="circle" color="red" text="评价"
										style="width: 300rpx;">
									</u-button>
								</view>
								<view class="public_button" v-if="item.status == 4&&item.payType!=5">
									<u-button :plain="true" shape="circle" color="red" text="申请退款" @click="Tk(item)">
									</u-button>
								</view>
							</view>
						</view>

					</view>
				</view>
			</scroll-view>
		</view>
		<paypass ref="yspay" @cancel="handleClose" @submit="submitpay"></paypass>
	</view>
</template>

<script>
	import paypass from "@/components/ys-paypass/ys-paypass.vue";
	import util from "@/util/index.js"
	export default {
		components: {
			paypass
		},
		data() {
			return {
				util: util,
				payType: {},
				tabList: [{
					name: '全部',
					indexValue: -2
				}, {
					name: '待付款',
					indexValue: 0
				}, {
					name: '待发货',
					indexValue: 1
				}, {
					name: '待收货',
					indexValue: 2
				}, {
					name: '待评价',
					indexValue: 3
				}, {
					name: '售后',
					indexValue: 4
				}],
				item: '',
				indexValue: "",
				SiteList: [],
				orderId: 0,
			}
		},
		methods: {
			dianji(item) {
				if (item.status == 2) {
					uni.navigateTo({
						url: '/pages/wlxq/wlxq?orderNo=' + item.orderNo
					})
				}
			},
			handleClose() {

			},
			submitpay(ex) {
				this.$http({
					url: '/member/balancePayment',
					data: {
						orderNo: JSON.stringify([this.payType.orderNo]),
						payPassword: ex.value,
					}
				}).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title: '支付成功',
						})
						this.SearchSite()
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'error'
						}).then(this.Passshow = true)
					}
				})
			},
			Tk(item) {
				let publicPrice = item.num * item.price
				// uni.showToast({
				// 	title:'该功能暂未开发',
				// 	icon:'error'
				// })
				uni.navigateTo({
					url: '/pages/refund/refund?orderNo=' + item.orderNo + '&id=' + item.id
				})
			},
			Pj(item) {
				uni.navigateTo({
					url: '/pages/evaluate/evaluate?orderNo=' + item.orderNo + '&goodsId=' + item.productId
				})
				this.SearchSite()
			},
			qrSH(item) {
				uni.showModal({
					cancelText: "取消",
					confirmText: "确认",
					title: "确认收货",
					content: '请再次确认是否收货！',
					confirmColor: "#88A58A",
					cancelColor: "#222222",
					success: res => {
						if (res.confirm) {
							this.$http({
								url: '/crmOrder/confirmReceipt',
								data: {
									orderNo: item.orderNo
								}
							}).then(res => {
								if (res.data.data == true) {
									uni.showToast({
										title: '收货成功'
									})
									this.SearchSite()
								}
							})
						}
					}
				})

			},
			DelOrder(item) {
				this.$http({
					url: '/crmOrder/cancelOrder',
					method: 'GET',
					data: {
						orderNo: item.orderNo
					}
				}).then(res => {
					if (res.data.data == true) {
						this.SearchSite()
					}
				})
			},
			Gopay(item) {
				this.payType = JSON.parse(JSON.stringify(item))
				let arr = [{
					payType: item.payType,
					orderNo: item.orderNo,
					price: item.price
				}]
				this.$http({
					url: '/member/balanceJudgment',
					data: {
						listStr: JSON.stringify(arr),
					}
				}).then(res => {
					if (res.data.code === 200) {
						let bool = true
						res.data.data.forEach(k => {
							if (k.flag !== 0) {
								bool = false
							}
						})
						if (bool) {
							this.$refs.yspay.show();
						} else {
							uni.showToast({
								title: "余额不足，请先充值",
								icon: 'error'
							})
							setTimeout(() => {
								this.handleClose()
							}, 1000)
						}
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'error'
						})
						this.handleClose()
					}
				})

			},
			SearchSite() {
				this.$http({
					url: '/crmOrder/selCrmOrderList',
					data: {
						statusId: this.indexValue
					}
				}).then(res => {
					this.SiteList = res.data.data
					this.SiteList.map(item => {
						item.Gjmoeny = item.num * item.price
					})

				})
			},
			ClickSite(index) {
				this.indexValue = index
				this.SearchSite()
			}
		},
		onLoad(option) {
			this.item = option.item
			this.indexValue = option.index
			// this.SearchSite();
		},
		onShow() {
			this.SearchSite()
		}
	}
</script>

<style>
	@import './index.css'
</style>
